package com.bw.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bw.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author 31629
 * @date 2025年08月30日 15:49
 */
@RestController
public class OrderInfoController {
    @Autowired
    private OrderInfoService orderInfoService;

    @RequestMapping("/s11")
    public JSONObject select1(){
        JSONObject res = new JSONObject();
        res.put("status",0);
        res.put("msg","");
        JSONObject data = new JSONObject();
        res.put("data",data);

        JSONArray categories = new JSONArray();
        JSONArray series = new JSONArray();
        data.put("categories",categories);
        data.put("series",series);

        JSONObject series_row1 = new JSONObject();
        series_row1.put("name","优惠总和");
        series.add(series_row1);

        JSONArray series_data = new JSONArray();
        series_row1.put("data",series_data);

        JSONObject series_row2 = new JSONObject();
        series_row2.put("name","排名");
        series.add(series_row2);

        JSONArray series_data2 = new JSONArray();
        series_row2.put("data",series_data2);

        List<Map<String, Objects>> maps = orderInfoService.select1();
        for (Map<String, Objects> map : maps) {
         categories.add(map.get("name"));
         series_data.add(map.get("sm"));
         series_data2.add(map.get("pm"));
        }
        return res;
    }
    @RequestMapping("/s22")
    public JSONObject select2(){
        JSONObject rest = new JSONObject();
        rest.put("status",0);
        rest.put("msg","");
        JSONObject data = new JSONObject();
        rest.put("data",data);

        JSONArray columns = new JSONArray();
        JSONArray rows = new JSONArray();

        data.put("columns",columns);
        data.put("rows",rows);

        JSONObject c1= new JSONObject();
        c1.put("name","名称");
        c1.put("id","name");

        JSONObject c2= new JSONObject();
        c2.put("name","下单金额");
        c2.put("id","s1");

        JSONObject c3= new JSONObject();
        c3.put("name","下单次数");
        c3.put("id","s2");

        JSONObject c4= new JSONObject();
        c4.put("name","下单人数");
        c4.put("id","s3");

        JSONObject c5= new JSONObject();
        c5.put("name","实收金额");
        c5.put("id","s4");

        JSONObject c6= new JSONObject();
        c6.put("name","退款成功金额");
        c6.put("id","s5");

        columns.add(c1);
        columns.add(c2);
        columns.add(c3);
        columns.add(c4);
        columns.add(c5);
        columns.add(c6);

        List<Map<String, Objects>> maps = orderInfoService.select2();
        for (Map<String, Objects> map : maps) {
            JSONObject row = new JSONObject();
            row.put("name",map.get("name"));
            row.put("s1",map.get("s1"));
            row.put("s2",map.get("s2"));
            row.put("s3",map.get("s3"));
            row.put("s4",map.get("s4"));
            row.put("s5",map.get("s5"));
            rows.add(row);
        }

        return rest;

    }
    @RequestMapping("/s33")
    public JSONObject select3(){
        JSONObject rest = new JSONObject();
        rest.put("status",0);
        rest.put("msg","");
        JSONObject data = new JSONObject();
        rest.put("data",data);

        JSONArray categories = new JSONArray();
        JSONArray series = new JSONArray();

        data.put("categories",categories);
        data.put("series",series);

        JSONObject series_row = new JSONObject();
        series_row.put("name","下单金额");
        series.add(series_row);

        JSONArray series_data = new JSONArray();
        series_row.put("data",series_data);

        JSONObject series_row1 = new JSONObject();
        series_row1.put("name","下单次数");
        series.add(series_row1);

        JSONArray series_data1 = new JSONArray();
        series_row1.put("data",series_data1);

        JSONObject series_row2 = new JSONObject();
        series_row2.put("name","下单人数");
        series.add(series_row2);

        JSONArray series_data2 = new JSONArray();
        series_row2.put("data",series_data2);

        List<Map<String, Objects>> maps = orderInfoService.select3();
        for (Map<String, Objects> map : maps) {
          categories.add(map.get("df"));
          series_data.add(map.get("s1"));
          series_data1.add(map.get("s2"));
          series_data2.add(map.get("s3"));
        }
        return rest;
    }
    @RequestMapping("/s44")
    public JSONObject select4(){
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");
        JSONObject data = new JSONObject();
        result.put("data",data);

        JSONArray categories = new JSONArray();
        JSONArray series = new JSONArray();
        data.put("categories",categories);
        data.put("series",series);

        JSONObject series_row1 = new JSONObject();
        series_row1.put("name","下单金额");
        series.add(series_row1);
        JSONArray row = new JSONArray();
        series_row1.put("data",row);

        JSONObject series_row2 = new JSONObject();
        series_row2.put("name","下单次数");
        series.add(series_row2);
        JSONArray row2 = new JSONArray();
        series_row2.put("data",row2);

        JSONObject series_row3 = new JSONObject();
        series_row3.put("name","下单人数");
        series.add(series_row3);
        JSONArray row3 = new JSONArray();
        series_row3.put("data",row3);

        List<Map<String, Objects>> maps = orderInfoService.select4();
        for (Map<String, Objects> map : maps) {
            categories.add(map.get("df"));
            row.add(map.get("sm"));
            row2.add(map.get("c"));
            row3.add(map.get("ci"));

        }
        return  result;
    }

}
